package realm.inorder.persistence.model;

import java.io.Serializable;

import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Version;

import org.openinsula.arena.dne.entity.Endereco;

import realm.inorder.persistence.visitor.PessoaVisitor;
import realm.inorder.persistence.visitor.impl.CpfCnpjPessoaVisitor;
import realm.inorder.persistence.visitor.impl.NomeRazaoSocialPessoaVisitor;

/**
 * 
 * @author realm
 */
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "tipo", length = 1, discriminatorType = DiscriminatorType.CHAR)
@DiscriminatorValue(value = "P")
public abstract class Pessoa implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	private Long id;

	@Version
	private Integer version;
	
	@Embedded
	private Endereco endereco;
	
	public abstract <T> T accept(PessoaVisitor<T> visitor);

	public String getNomeRazaoSocial() {
		return this.accept(new NomeRazaoSocialPessoaVisitor());
	}

	public String getCpfCnpj() {
		return this.accept(new CpfCnpjPessoaVisitor());
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public Endereco getEndereco() {
		return endereco;
	}

	public void setEndereco(Endereco endereco) {
		this.endereco = endereco;
	}

}
